package com.hyf.zookeeper.core;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;

public class ZKDelete {

    private static ZooKeeper zk;

    private static ZookeeperConnection zkConn;

    //删除一个目录，目录下没有子节点
    public static void delete(String path) throws KeeperException, InterruptedException {
        zk.delete(path,zk.exists(path,true).getVersion());
    }

    public static void main(String[] args){
        String path="/MyFirstZnode";

        zkConn=new ZookeeperConnection();
        try {
            zk=zkConn.connect("47.93.157.178:12181");
            delete(path);
            System.out.println("delete success");
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (KeeperException e) {
            e.printStackTrace();
        }
    }
}
